<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :okButtonProps="{ props: { disabled: disableSubmit } }"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-alert message="结算后将自动修改订单状态，确认结算？" banner />
        <br/>
        <a-form-item    label="结算费用">
<!--          <a-alert type="info" show-icon style="margin-top: 10px"  :message="'接单金额:'+this.model.takeMoney"  />-->
          <a-alert type="info" show-icon style="margin-top: 10px" :message="'普通用户费用:'+this.model.cost"  />
<!--          <a-alert type="info" show-icon style="margin-top: 10px" :message="'子管理提成数据:'+this.model.takeManagerMoney"  />-->
        </a-form-item>
          <a-form-item    label="合作用户支付宝收款码">
            <img v-if="MoneyImgSrc" alt="example" style="width: 45%;height:45%;margin-left: 20%" :src="getAvatarView(MoneyImgSrc)" />
            <a-alert type="info" show-icon v-else message="未上传支付宝收款码"  />
          </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { httpAction } from '@/api/manage'
  import { queryUser} from '@/api/api'
  import pick from "lodash.pick";
  export default {
    name: "OrderFormModal",
    data () {
      return {
        title:"操作",
        visible: false,
        MoneyImgSrc:'',
        model: {
          cost:0,
          takeManagerMoney:0,
          takeMoney:0,
        },
        disableSubmit:false,
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules:{
          orderStatus:{
            rules: [{
              required: true, message: '请选择订单状态!'
            }]
          },
        },
        url: {
          imgerver: window._CONFIG['domianURL'] + "/sys/common/view",
          add: "/orderForm/orderForm/add",
          edit: "/orderForm/orderForm/edit",
        },
      }
    },
    created () {

    },
    methods: {
      getAvatarView: function (avatar) {
        return this.url.imgerver + "/" + avatar;
      },
      add () {
        this.edit({});
      },
      edit (record) {
        this.getUserMoneyImg(record.takeOrders);
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;

      },
      getUserMoneyImg(username){
        let that=this;
        queryUser({username:username}).then((res)=>{
          if(res.success){
            that.MoneyImgSrc =res.result.avatar;
          }
        });
      },
      close () {
        this.$emit('ok');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            httpurl+=this.url.edit;
            method = 'put';
            let formData = Object.assign(this.model, values);
            formData.settlementStatus=1;
            formData.orderStatus=5;
            console.log("formData-->",formData);
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })

          }
        })
      },
      handleCancel () {
        this.close()
      },


    }
  }
</script>

<style scoped>

</style>